<%="<"%>%- if <%= config.model == "crecto" ? "changeset" : @name %>.errors %>
  <ul class="errors">
  <%="<"%>%- <%= config.model == "crecto" ? "changeset" : @name %>.errors.each do |error| %>
    <li><%="<"%>%= error.to_s %></li>
  <%="<"%>%- end %>
  </ul>
<%="<"%>%- end %>

<%="<"%>%- action = (<%= @name %>.id ? "/<%= name_plural %>/" + <%= @name %>.id.to_s : "/<%= name_plural %>") %>
<form action="<%="<"%>%= action %>" method="post">
  <%="<"%>%= csrf_tag %>
  <%="<"%>%- if <%= @name %>.id %>
  <input type="hidden" name="_method" value="patch" />
  <%="<"%>%- end %>

<% @fields.reject{|f| f.hidden }.each do |field| -%>
  <div class="form-group">
<% case field.type
   when "text" -%>
    <%="<"%>%= text_area(name: "<%= field.name -%>", content: <%= @name %>.<%= field.name %>, placeholder: "<%= field.name.capitalize %>", class: "form-control", size: "30x10") -%>
<% when "boolean" -%>
  <%="<"%>%= label(<%=":#{field.name}"%>) do
    check_box(<%=":#{field.name}, checked: #{@name}.#{field.name}.to_s == \"1\""%>,
              class: "form-check-input")
  end -%>
<% when "reference" -%>
    <%="<"%>%= label(<%=":#{field.name}"%>) -%>
    <%="<"%>%= select_field(name: "<%= field.name %>_id", collection: <% if config.model == "crecto" %>Repo.all(<%= field.class_name %>)<% else %><%= field.class_name %>.all<% end %>.map{|<%= field.name %>| [<%= field.name %>.id, <%= field.name %>.id]}, selected: <%= @name %>.<%= field.name %>_id, class: "form-control") -%>
<% else -%>
    <%="<"%>%= text_field(name: "<%= field.name %>", value: <%= @name %>.<%= field.name %>, placeholder: "<%= field.name.capitalize %>", class: "form-control") -%>
<% end -%>
  </div>
<% end -%>
  <%="<"%>%= submit("Submit", class: "btn btn-success btn-sm") -%>
  <%="<"%>%= link_to("Back", "/<%= name_plural %>", class: "btn btn-light btn-sm") -%>
</form>
